package com.xxl.job.executor.service.jobhandler;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.executor.dao.DeviceDao;
import com.xxl.job.executor.model.Device;
import groovy.util.logging.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class MtimRefreshJob {

    @Resource
    private DeviceDao deviceDao;

    @XxlJob("refreshJobHandler")
    public void refreshJobHandler() throws Exception {
        XxlJobHelper.log("XXL-JOB, Hello refreshJobHandler.");

        for (int i = 0; i < 5; i++) {
            XxlJobHelper.log("beat at:" + i);
            TimeUnit.SECONDS.sleep(2);
        }
        // default success
    }

//    @DS("second")
    @XxlJob("refreshDeviceJobHandler")
    public void refreshDeviceJobHandler() throws Exception {
        XxlJobHelper.log("XXL-JOB, Hello refreshDeviceJobHandler!");
        List<Device> deviceList = this.deviceDao.queryAllDevice();

        XxlJobHelper.log(deviceList.toString());

//        this.dataAlert.run();

        //get device info
    }
}
